package com.hoyo.utils;

import java.util.Base64;

import com.hoyo.common.AppConstant;
import com.qiniu.util.Auth;
import com.qiniu.util.StringMap;
import com.qiniu.util.UrlSafeBase64;

public class TokenUtils {
	
	private static final long expireSeconds = 3600;
	
	private static final Auth auth = Auth.create(AppConstant.Qiniuyun.accessKey, AppConstant.Qiniuyun.secretKey);
	
	public static String generatePrivateUploadToken(){
		
		StringMap putPolicy = new StringMap();
		return auth.uploadToken(AppConstant.Qiniuyun.privateBucketName, null, expireSeconds, putPolicy);
	}
	
	public static String generatePublicUploadToken(){
		
		StringMap putPolicy = new StringMap();
		return auth.uploadToken(AppConstant.Qiniuyun.publicBucketName, null, expireSeconds, putPolicy);
	}
	
	public static String generateDownloadToken(String filePath){
		return auth.privateDownloadUrl(filePath);
	}
	
	public static StringMap authorization(String url, byte[] body, String contentType){
		return auth.authorization(url, body, contentType);
	}
	
	public static void main(String[] args) {
		String url = "rs.qiniu.com/batch";
		String body = "op=/delete/<EncodedEntryURI>&op=/delete/<EncodedEntryURI>";
		String contentType="application/x-www-form-urlencoded";
		StringMap map = TokenUtils.authorization(url, body.getBytes(), contentType);
		String string = map.get("Authorization").toString();
		System.out.println(string);
	}
}
